import MySQLdb,json
from datetime import datetime
import time

ne=[]
conn=MySQLdb.connect(host="172.16.100.31",user="root",passwd="admin",db="rainbow_3_0")
cursor=conn.cursor()
cursor.execute("SELECT * FROM ne where neid not in(select neid from rcpe) order by ne_neid,neid")
[ne.append((x[0],x[1])) for x in cursor.fetchall()]
cursor.close()
conn.close()

# ne=[(1,None),(2,1),(3,1),(6,5),(5,None),(9,2)]
# tree=[(2,1),(3,1),(6,5),(9,1)]
# print json.dumps(tree)
tree=[]

def getParentId(id):
  for x in ne:
    if x[0]==id:
      return x[1]
def getRootId(id):
  tmp=id
  while tmp<>None:
    tmp=getParentId(id)
    if tmp<>None:
      id=tmp
  return id
      
s=time.time()      
for x in ne:
  if x[1]<>None:
    root=getRootId(x[1])
    tree.append((x[0],root))
e=time.time()
# print tree
print e-s      
print len(tree)



    